package ${packageName}.dto;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * ${tableInfo.tableComment}数据传输对象
 * 
 * @author ${tableInfo.author}
 * @date ${.now?string("yyyy-MM-dd")}
 */
public class ${tableInfo.className}DTO {
    
<#list tableInfo.columns as column>
    <#if !column.isPrimaryKey>
    /**
     * ${column.columnComment}
     */
    <#if column.isRequired>
    @NotNull(message = "${column.columnComment}不能为空")
    </#if>
    private ${getJavaType(column.columnType)} ${getFieldName(column.columnName)};
    
    </#if>
</#list>
    // Getters and Setters
<#list tableInfo.columns as column>
    <#if !column.isPrimaryKey>
    public ${getJavaType(column.columnType)} get${getFieldName(column.columnName)?cap_first}() {
        return ${getFieldName(column.columnName)};
    }

    public void set${getFieldName(column.columnName)?cap_first}(${getJavaType(column.columnType)} ${getFieldName(column.columnName)}) {
        this.${getFieldName(column.columnName)} = ${getFieldName(column.columnName)};
    }
    
    </#if>
</#list>
    @Override
    public String toString() {
        return "${tableInfo.className}DTO{" +
<#list tableInfo.columns as column>
    <#if !column.isPrimaryKey>
            "${getFieldName(column.columnName)}=" + ${getFieldName(column.columnName)} +
    <#if column_has_next>
            ", " +
    <#else>
            "}";
    </#if>
    </#if>
</#list>
    }
}

<#function getJavaType dbType>
    <#switch dbType?lower_case>
        <#case "varchar">
        <#case "char">
        <#case "text">
        <#case "longtext">
            <#return "String">
        <#case "int">
        <#case "integer">
            <#return "Integer">
        <#case "bigint">
            <#return "Long">
        <#case "decimal">
        <#case "numeric">
        <#case "double">
            <#return "Double">
        <#case "float">
            <#return "Float">
        <#case "boolean">
        <#case "tinyint">
            <#return "Boolean">
        <#case "datetime">
        <#case "timestamp">
            <#return "LocalDateTime">
        <#case "date">
            <#return "LocalDate">
        <#case "time">
            <#return "LocalTime">
        <#default>
            <#return "String">
    </#switch>
</#function>

<#function getFieldName columnName>
    <#assign fieldName = columnName?lower_case>
    <#assign parts = fieldName?split("_")>
    <#assign result = parts[0]>
    <#list parts as part>
        <#if part_index gt 0>
            <#assign result = result + part?cap_first>
        </#if>
    </#list>
    <#return result>
</#function> 